cd "dir:"

* Replicates Table 4
* Set value of phi as necessary 

clear 

 global nobs = 60
 global nmc = 10000
 set seed 5000
 set obs $nobs
 gen id = _n
 tsset id
 
 * Set the values of the parameters
 scalar ecmsig = -1.645
 scalar ecmMCVm1 = -3.27

 scalar up = 1.96
 scalar lp = -1.96
 scalar alpha = .05
 scalar phi = .6

 * Generating random starting values for DV
 gen dv1 = 0
 gen iv1 = 0
 
 * generating errors
 gen q = .
 gen u = . 
 
 tempname sim

 postfile `sim' m1a1 m1sea1 m1ta1 m1b0 m1se0 m1tb0 m1b1 m1se1 m1tb1  m1asig m1asigMCV m1dxsig m1xlsig m1dxecm m1dxecmMCV m1lxecm m1lxecmMCV  ///
 			  using MC_TBL4, replace     
 
 quietly {
 forvalues i = 1/$nmc {
 replace q = rnormal()
 replace u = rnormal()
 
 replace dv1 = phi*l.dv1 + q in 2/$nobs
 replace iv1 = u in 2/$nobs
 
 
 * Model 1 *
 reg d.dv1 l.dv1 d.iv1 l.iv1
 
 * Model 1 coefficient values
 scalar m1a1 = _b[l.dv1]
 scalar m1b0 = _b[d.iv1]
 scalar m1b1 = _b[l.iv1]

 * Model 1 standard errors
 scalar m1sea1 = _se[l.dv1]
 scalar m1se0 = _se[d.iv1]
 scalar m1se1 = _se[l.iv1]
 
 * Model 1 t-statistics
 scalar m1ta1 = m1a1/m1sea1
 scalar m1tb0 = m1b0/m1se0
 scalar m1tb1 = m1b1/m1se1

 * Calculating significance totals (Model 1)
 scalar m1asig = m1ta1<ecmsig
 scalar m1asigMCV = m1ta1<=ecmMCVm1
 scalar m1dxsig = (m1tb0>up | m1tb0<lp) 
 scalar m1xlsig = (m1tb1>up | m1tb1<lp)  
 scalar m1dxecm = (m1ta1<ecmsig & (m1tb0>up | m1tb0<lp)) 
 scalar m1dxecmMCV = (m1ta1<ecmMCVm1 & (m1tb0>up | m1tb0<lp)) 
 scalar m1lxecm = (m1ta1<ecmsig & (m1tb1>up | m1tb1<lp)) 
 scalar m1lxecmMCV = (m1ta1<ecmMCVm1 & (m1tb1>up | m1tb1<lp)) 
 
 
 
 post `sim' (m1a1) (m1sea1) (m1ta1) (m1b0) (m1se0) (m1tb0) (m1b1) (m1se1) (m1tb1) (m1asig) (m1asigMCV) (m1dxsig) (m1xlsig) (m1dxecm) (m1dxecmMCV) (m1lxecm) (m1lxecmMCV)  ///
 		
 }
 }
 postclose `sim'

 use MC_TBL4, clear
 
 sum m1asig m1asigMCV m1a1 m1dxsig m1xlsig m1dxecm m1dxecmMCV m1lxecm m1lxecmMCV
 
 
